package com.example.yunJie.digitalSentry.control;

import com.example.yunJie.digitalSentry.entity.EquipmentEntity;
import com.example.yunJie.digitalSentry.entity.MarketEntity;
import com.example.yunJie.digitalSentry.service.EquipmentService;
import com.example.yunJie.digitalSentry.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Equipment")
public class EquipmentControl {
    @Autowired
    private EquipmentService equipmentService;
    @Autowired
    private MarketService marketService;

    @RequestMapping("/add")
    public void insert(EquipmentEntity equipmentEntity) {
        MarketEntity idByMarketName = marketService.findIdByMarketName(equipmentEntity.getMarketName());
        equipmentEntity.setMarketId(String.valueOf(idByMarketName.getId()));
        equipmentService.insert(equipmentEntity);
    }

    @RequestMapping("/update")
    public int update(EquipmentEntity equipmentEntity) {
        MarketEntity idByMarketName = marketService.findIdByMarketName(equipmentEntity.getMarketName());
        equipmentEntity.setMarketId(String.valueOf(idByMarketName.getId()));
        return equipmentService.update(equipmentEntity);
    }

    @RequestMapping("/deleteById")
    public int deleteById(String id) {
        return equipmentService.deleteById(id);
    }

    @RequestMapping("/deleteIdList")
    public int deleteIdList(List<Integer> id) {
        return equipmentService.deleteIdList(id);
    }

    @RequestMapping("/findId")
    public EquipmentEntity findId(String id) {
        return equipmentService.findId(id);
    }

    @RequestMapping("/findAll")
    List<EquipmentEntity> findAll(EquipmentEntity equipmentEntity) {
        List<EquipmentEntity> all = equipmentService.findAll(equipmentEntity);
//        for (EquipmentEntity equipmentEntity1y:all){
//            System.out.println(equipmentEntity1y);
//        }
        return all;
    }

}
